package com.ruoyi.pet.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pet.domain.PetDiagnosis;
import com.ruoyi.pet.service.IPetDiagnosisService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病例Controller
 * 
 * @author ruoyi
 * @date 2023-09-01
 */
@RestController
@RequestMapping("/pet/diagnosis")
public class PetDiagnosisController extends BaseController
{
    @Autowired
    private IPetDiagnosisService petDiagnosisService;

    /**
     * 查询病例列表
     */
    @PreAuthorize("@ss.hasPermi('pet:diagnosis:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetDiagnosis petDiagnosis)
    {
        startPage();
        List<PetDiagnosis> list = petDiagnosisService.selectPetDiagnosisList(petDiagnosis);
        return getDataTable(list);
    }

    /**
     * 导出病例列表
     */
    @PreAuthorize("@ss.hasPermi('pet:diagnosis:export')")
    @Log(title = "病例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetDiagnosis petDiagnosis)
    {
        List<PetDiagnosis> list = petDiagnosisService.selectPetDiagnosisList(petDiagnosis);
        ExcelUtil<PetDiagnosis> util = new ExcelUtil<PetDiagnosis>(PetDiagnosis.class);
        util.exportExcel(response, list, "病例数据");
    }

    /**
     * 获取病例详细信息
     */
//    @PreAuthorize("@ss.hasPermi('pet:diagnosis:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(petDiagnosisService.selectPetDiagnosisById(id));
    }

    /**
     * 新增病例
     */
    @PreAuthorize("@ss.hasPermi('pet:diagnosis:add')")
    @Log(title = "病例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetDiagnosis petDiagnosis)
    {
        return toAjax(petDiagnosisService.insertPetDiagnosis(petDiagnosis));
    }

    /**
     * 修改病例
     */
    @PreAuthorize("@ss.hasPermi('pet:diagnosis:edit')")
    @Log(title = "病例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetDiagnosis petDiagnosis)
    {
        return toAjax(petDiagnosisService.updatePetDiagnosis(petDiagnosis));
    }

    /**
     * 删除病例
     */
    @PreAuthorize("@ss.hasPermi('pet:diagnosis:remove')")
    @Log(title = "病例", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(petDiagnosisService.deletePetDiagnosisByIds(ids));
    }
}
